package com.time.workshop.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener; 
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.time.workshop.API;
import com.time.workshop.App;
import com.time.workshop.BaseConstant;
import com.time.workshop.R;
import com.time.workshop.SuperActivity;
import com.time.workshop.bean.RequestOrder;
import com.time.workshop.injector.Injector;
import com.time.workshop.injector.V;
import com.time.workshop.utils.CommonUtils;
import com.time.workshop.utils.LaoBanDialog;
import com.time.workshop.utils.NewToast;
import com.time.workshop.utils.OnClickOKListener;
/**
 * 许愿盒子
 * @author wangfeng
 *
 */
public class XuYuanActivity extends SuperActivity implements OnClickListener{
	@V
	private ImageView img_login_back;
	@V
	private TextView cancelTextView,sureTextView,title;
	@V
	private EditText maoshu,nameEditText,phoneEditText;
	@V
	private RelativeLayout rl_price;
	@V
	private LinearLayout ll_xuyuan;
	private String content,name,phone;
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.activity_custommade);
		init();
	}

	private void init() {
		Injector.getInstance().inject(this);
		img_login_back.setOnClickListener(this);
		cancelTextView.setOnClickListener(this);
		sureTextView.setOnClickListener(this);
		ll_xuyuan.setBackgroundResource(R.drawable.xuyuan);
		rl_price.setVisibility(View.GONE);
		title.setText(getResources().getString(R.string.xuyuan));
		title.setTextColor(getResources().getColor(R.color.white));
		maoshu.setHint(getResources().getString(R.string.hint_xuyuancontent));
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_login_back:
			CommonUtils.hide(this);
			back();
			break;
		case R.id.cancelTextView:
			CommonUtils.hide(this);
			back();
			break;
		case R.id.sureTextView:
			content = maoshu.getText().toString().trim();
			name = nameEditText.getText().toString().trim();
			phone = phoneEditText.getText().toString().trim();
			if ("".equals(CommonUtils.isNull(content))) {
				NewToast.makeText(getApplicationContext(), getResources().getString(R.string.toast_yuanwang));
				return;
			}
			if ("".equals(CommonUtils.isNull(name))) {
				NewToast.makeText(getApplicationContext(), getResources().getString(R.string.toast_name));
				return;
			}
			if (!CommonUtils.isMobile(phone)) {
				NewToast.makeText(getApplicationContext(), getResources().getString(R.string.toast_phone));
				return;
			}
			showConfirmDialog();
			break;
		default:
			break;
		}
	}

	private LaoBanDialog dlg;
	/**
	 * 显示  Dailog 
	 */
	private void showConfirmDialog() {

		dlg = new LaoBanDialog(XuYuanActivity.this);
		if (dlg.isShowing()) {
			dlg.dismiss();
			return;
		}
		dlg.onCreate();
		dlg.setOnClickOK(new OnClickOKListener() {

			@Override
			public void setOnClickOK() {
//				Intent in = new Intent(XuYuanActivity.this,ConfirmOrderActivity.class);
//				in.putExtra("content", content);
//				in.putExtra("name", name);
//				in.putExtra("phone", phone);
//				startActivity(in, true);
//				dlg.dismiss();
//				finish();
				dlg.dismiss();
				RequestOrder requestOrder = new RequestOrder();
				requestOrder.ORDER_TYPE = "XYHZ";
				requestOrder.contactor_person = name;
				requestOrder.contactor_phone = phone;
				requestOrder.remark = content;
				API.submitOrder(requestOrder, XuYuanActivity.this);
			}
		});
	}
}
